/**
 * Created by LC on 2019/11/7
 */
package com.hw.paltfrom.service.doncutor;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.exception.HWSystemException;
import com.hw.paltfrom.mapper.HwBaseWorkflowMapper;
import com.hw.paltfrom.mapper.HwCommandWorkflowMapper;
import com.hw.paltfrom.pojo.HwBaseWorkflow;
import com.hw.paltfrom.pojo.HwCommandWorkflow;
import com.hw.paltfrom.rescode.HWSystemCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BaseWorkflowService {
    @Autowired
    private HwBaseWorkflowMapper baseWorkflowMapper;

    /**
     * 得到下一办理阶段
     *
     * @param workFolwCode  数字
     * @param workFlowType  字母
     * @return 下一阶段code, name
     */
    public HwBaseWorkflow getPresentWorkflow(String workFolwCode, String workFlowType) {

        Wrapper<HwBaseWorkflow> wrapper = new EntityWrapper<>();
        wrapper.eq("WorkFlow_Code", workFolwCode).eq("WorkFlow_Type", workFlowType);

        //查询下一阶段
        List<HwBaseWorkflow> hwBaseWorkflows = baseWorkflowMapper.selectList(wrapper);

        if (hwBaseWorkflows.size() == 0){
            throw new HWSystemException(HWSystemCode.PARAMS_ERROR);
        }
        HwBaseWorkflow hwBaseWorkflow = hwBaseWorkflows.get(0);

        return hwBaseWorkflow;
    }

    /**
     * 得到上一阶段
     *
     * @param workflowNextcode
     * @param workFlowType
     * @return 上一阶段code, name
     */
    public HwBaseWorkflow getNextWorkflow(String workflowNextcode, String workFlowType) {
        Wrapper<HwBaseWorkflow> wrapper = new EntityWrapper<>();
        wrapper.eq("WorkFlow_NextCode", workflowNextcode).eq("WorkFlow_Type", workFlowType);
        //查询上一阶段
        List<HwBaseWorkflow> hwBaseWorkflows = baseWorkflowMapper.selectList(wrapper);
        if (hwBaseWorkflows.size() == 0){
            throw new HWSystemException(HWSystemCode.PARAMS_ERROR);
        }
        HwBaseWorkflow hwBaseWorkflow = hwBaseWorkflows.get(0);
//        String workFolwCode = hwBaseWorkflow.getWorkflowCode();
//        String workflowCodename = hwBaseWorkflow.getWorkflowCodename();
//        Map<String, String> map = new HashMap<>();
//        //返回上一阶段code,name
//        map.put("workfolwCode", workFolwCode);
//        map.put("workflowCodename", workflowCodename);
        return hwBaseWorkflow;
    }

    /**
     * 得到第二阶段
     * @param workFlowType
     * @return 初始化workflowCode
     */
    public HwBaseWorkflow getStartBaseWorkflow(String workFlowType){
        Wrapper<HwBaseWorkflow> wrapper = new EntityWrapper<>();
        wrapper.eq("WorkFlow_Code", "01").eq("WorkFlow_Type", workFlowType);
        List<HwBaseWorkflow> hwBaseWorkflows = baseWorkflowMapper.selectList(wrapper);
        if (hwBaseWorkflows.size() == 0){
            throw new HWSystemException(HWSystemCode.PARAMS_ERROR);
        }
        HwBaseWorkflow hwBaseWorkflow = hwBaseWorkflows.get(0);
        return hwBaseWorkflow;
    }
}
